package com.gdpu.component;

import com.gdpu.mapper.OmsOrderMapper;
import com.gdpu.model.OmsOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author:weiming
 * @Date:2021/6/22
 */
@Component
public class CancelMessageSender {
    private static Logger LOGGER = LoggerFactory.getLogger(CancelMessageSender.class);
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendDelayCancelMessage(Integer orderId){

        rabbitTemplate.convertAndSend("orderExchange", "ttlMessage",orderId , new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setExpiration(String.valueOf(1*60*1000));
                return message;
            }
        });
        LOGGER.info("send orderId:{}",orderId);
    }

}
